package com.air.antispider.stream.dataprocess.businessprocess

import com.air.antispider.stream.common.bean.{BookRequestData, CoreRequestParams, ProcessedData, QueryRequestData, RequestType}
import com.air.antispider.stream.dataprocess.constants.TravelTypeEnum.TravelTypeEnum

/**
  * 数据打包,将散乱的数据封装为ProcessedData
  */
object DataPackage {
  def dataPackage(sourceData: String,
                  requestMethod: String,
                  request: String,
                  remoteAddr: String,
                  httpUserAgent: String,
                  timeIso8601: String,
                  serverAddr: String,
                  isFreIP: Boolean,
                  requestType: RequestType,
                  travelType: TravelTypeEnum,
                  cookieValue_JSESSIONID: String,
                  cookieValue_USERID: String,
                  queryRequestData: Option[QueryRequestData],
                  bookRequestData: Option[BookRequestData],
                  httpReferrer: String): ProcessedData = {
    //创建核心请求参数:requestParams
//    flightDate: String, depcity: String, arrcity: String

    //航班飞行日期
    var flightDate: String = ""
    //始发地
    var depcity: String = ""
    //目的地
    var arrcity: String = ""

    queryRequestData match {
      case Some(queryRequest) => {
        flightDate = queryRequest.flightDate
        depcity = queryRequest.depCity
        arrcity = queryRequest.arrCity
      }
      case None =>
        //如果查询没有匹配上,那么看看预定能不能匹配上
        bookRequestData match {
          case Some(bookRequest) => {
            flightDate = bookRequest.flightDate.mkString
            depcity = bookRequest.depCity.mkString
            arrcity = bookRequest.arrCity.mkString

          }
          case None =>
        }
    }

    //构建核心请求参数
    val requestParams = CoreRequestParams(flightDate, depcity, arrcity)
    ProcessedData(sourceData, requestMethod,request, remoteAddr, httpUserAgent, timeIso8601,
      serverAddr, isFreIP, requestType, travelType, requestParams, cookieValue_JSESSIONID, cookieValue_USERID,queryRequestData, bookRequestData, httpReferrer)
  }








}
